window.onload=function(){
	bannerSlide();
	textSubstring($(".text100"),100);
	textSubstring($(".text140"),140);
	textSubstring($(".text110"),110);
	textSubstring($(".text55"),55);
}

function bannerSlide(){
	var slideNum=$(".banner_ul li").length;
	var slideWidth=$(".banner_ul li img").width();
	var n=0;
	var btnNum=0;
	$(".dot").eq(0).css("background","#ff0000").siblings("li").css("background","#a0a0a0");
	function go(){
		if(n<slideNum-1){
			n=n+1;
			$(".banner_ul").animate({left:-n*slideWidth},500);
			
		} else{
			
			$(".banner_ul").css({left:0});
			n=1;
			$(".banner_ul").animate({left:-n*slideWidth},500);
			// n=1;
		}
		if(btnNum<slideNum-2){
			btnNum++
			$(".dot").eq(btnNum).css("background","#ff0000").siblings("li").css("background","#a0a0a0");
		} else{
			btnNum=0;
			$(".dot").eq(btnNum).css("background","#ff0000").siblings("li").css("background","#a0a0a0");
		}


	}

	var bannerTimer=setInterval(go,3000);

	$(".banner").mouseenter(function(){
		clearInterval(bannerTimer);
	})

	$(".banner").mouseleave(function(){
		bannerTimer=setInterval(go,3000);
	})
	
	// 点击按钮，切换banner图
	$(".dot").click(function(){
		$(this).css("background","#ff0000").siblings("li").css("background","#a0a0a0");
		$(".banner_ul").animate({left:-$(this).index()*slideWidth},500);

	})

}

function textSubstring(oText,length){

	oText.each(function(){
		if ($(this).text().length>length) {
			$(this).text($(this).text().substring(0,length)+"...")
		}
	})
}